<?php

namespace app\common\model;

use think\Model;

/**
 * Order
 */
class Order extends Model
{
    // 表名
    protected $name = 'order';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = true;


    public function getCompleteDamageImagesAttr($value): array
    {
        if ($value === '' || $value === null) return [];
        if (!is_array($value)) {
            return explode(',', $value);
        }
        return $value;
    }

    public function setCompleteDamageImagesAttr($value): string
    {
        return is_array($value) ? implode(',', $value) : $value;
    }

    public function getStartImagesAttr($value): array
    {
        if ($value === '' || $value === null) return [];
        if (!is_array($value)) {
            return explode(',', $value);
        }
        return $value;
    }

    public function setStartDamageImagesAttr($value): string
    {
        return is_array($value) ? implode(',', $value) : $value;
    }

    public function car(): \think\model\relation\BelongsTo
    {

        return $this->belongsTo(CarView::class, 'car_id', 'id');
    }

    public function startStore(): \think\model\relation\BelongsTo
    {
        return $this->belongsTo(\app\admin\model\Store::class, 'start_store_id', 'id');
    }

    public function startStaff(): \think\model\relation\BelongsTo
    {
        return $this->belongsTo(\app\admin\model\Staff::class, 'start_staff_id', 'id');
    }

    public function completeStaff(): \think\model\relation\BelongsTo
    {
        return $this->belongsTo(\app\admin\model\Staff::class, 'complete_staff_id', 'id');
    }
}